        subroutine preGMRES(H,dudQ,N_eq,numpar,ITER,FRES)       

        IMPLICIT DOUBLE PRECISION (A-H,O-Z)
        INCLUDE 'param_dim.inc'


        DIMENSION XIS(NX),U(NX,NBX+1),HBAR(NBX+1,NBX+1),EBAR(NBX+1)
        DIMENSION EEBAR(NBX+1),YIP(NBX+1),CE(NBX+1),ES(NBX+1),XISA(NX)	

        double precision H(N_eq,N_eq),dudq(N_eq,numpar),DFI(NX)

        integer fres,iter

! 
!         write(*,*)'Antes solve gmres'
!         do i=1,N_eq
!             write(*,*)(dudq(i,j),j=1,numpar)
!         enddo


!         do j=1,numpar
!             r=0.
!             do i=1,N_eq
!                     r = r + dudq(i,j)**2
!             enddo
!             write(*,*)j,'Antes solve gmres |b|= ',r
!         enddo



        do j=1,numpar

            do i=1,N_eq
                dfi(i) = dudQ(i,j)
            enddo

            !2) GMRES
            NB=    NBX
            LMAX=  3
            ICONV= 0
            IRP=   0
            CALL GMRES(H,dfi,XIS,XISA,U,EBAR,
     &            EEBAR,HBAR,YIP,CE,ES,ETOL,N_eq,NB,NB,LMAX,
     &              ICONV,ITER,IRP,FRES)
            IF(ICONV.EQ.0)STOP'CONVERGENCIA NAO ATINGIDA - gmres'
            !fim do solve com GMRES


            do i=1,N_eq
                dudQ(i,j) = dfi(i) 
            enddo

        enddo
    

! !         write(*,*)j,'Apos solve gmres'
!         do j=1,numpar
!             r=0.
!             do i=1,N_eq
!                     r = r + dudq(i,j)**2
!             enddo
! !             write(*,*)j,'Apos solve gmres |b|= ',r


!         enddo



        return
        end

